package com.crazy.appium.testcases;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.crazy.appium.action.HeadImgActions;
import com.crazy.appium.action.LoginActions;
import com.crazy.appium.action.ProductBuy;
import com.crazy.appium.datadriver.ExcelUtil;
import com.crazy.appium.testng.Assertion;
import com.crazy.appium.utils.GetLocatorUtils;
import com.crazy.appium.utils.ImageUtil;

/**
 * @author 沙陌  qq2879897713
 *
 */
public class LoginTests extends TestBase{
	
	private LoginActions loginActions;
	
	@Test(dataProvider="getData")
	public void test001_login(String lineNumber,String caseName,String username,String pwd,String assertValue,String fileName) throws Exception{
		ExcelUtil excel=new ExcelUtil("C:/Users/LXG/Desktop/liecai.xlsx");
		Assertion assertion=new Assertion(driver);
		loginActions=new LoginActions(driver, platform);
		loginActions.login(username,pwd);
		System.out.println("assertValue========="+assertValue);
		if(assertValue.contains("attribute")){
			String[] assertValues=assertValue.split("=");
			String attrValue=loginActions.loginPage.getLogin_btn().getAttribute(assertValues[1]);
			//Assert.assertEquals(attrValue.equalsIgnoreCase(assertValues[2]), true);
			System.out.println("attrValue========="+attrValue);
			System.out.println("assertValues[2]==========="+assertValues[2]);
			try {
				assertion.assertEquals(attrValue.equalsIgnoreCase(assertValues[2]), true, fileName);
				excel.setCellData(Integer.valueOf(lineNumber), 7, "测试成功", "login", true);
			} catch (Error e) {
				// TODO: handle exception
				excel.setCellData(Integer.valueOf(lineNumber), 7, "测试失败", "login", false);
				assertion.fail(fileName, caseName+"失败");
			}
		}
		else{
			try {
				assertion.assertEquals(driver.getPageSource().contains(assertValue), true, fileName);
				excel.setCellData(Integer.valueOf(lineNumber), 7, "测试成功", "login", true);
			} catch (Error e) {
				// TODO: handle exception
				excel.setCellData(Integer.valueOf(lineNumber), 7, "测试失败", "login", false);
				assertion.fail(fileName, caseName+"失败");
			}
		}
		//String text=loginActions.minePage.getUserPhone();

		
	}
	@Test(enabled=false)
	public void test002_headImgUplod() throws Exception{
		HeadImgActions head=new HeadImgActions(driver, platform);
		int j=head.headImaUpload();
		boolean flag=ImageUtil.compareImg("images/img"+j+".png", "images/imgNew"+j+".png", 100f);
		Assert.assertEquals(true, flag);
	}
	@Test(enabled=false)
	public void test003_buyproduct(){
		ProductBuy buy=new ProductBuy(driver, platform);
		buy.buyProduct();
	}
	
	

}
